export default {
  namespaced: true,
  state: () => ({
    address: JSON.parse(uni.getStorageSync('address') || '{}'),
    // token:uni.getStorageSync('token')||'',
    token: '12341451',
    userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
    redirectInfo: null
  }),

  // 方法
  mutations: {
    updateRedirectInfo(state, info) {
      state.redirectInfo = info
    },
    //更新token
    updateToken(state, token) {
      state.token = token
      this.commit('muser/saveTokenToStorage')
    },
    saveTokenToStorage(state) {
      uni.setStorageSync('token', state.token)
    },
    //更新用户信息
    updateUserInfo(state, userInfo) {
      state.userInfo = userInfo
      this.commit('muser/saveUserInfoToStorage')
    },
    //用户信息持久化
    saveUserInfoToStorage(state) {
      uni.setStorageSync('userInfo', JSON.stringify(state.userInfo))
    },
    // 更新收货地址
    updateAddress(state, address) {
      state.address = address
      this.commit('muser/saveAddressToStorage')
    },
    //数据持久化 
    saveAddressToStorage(state) {
      uni.setStorageSync('address', JSON.stringify(state.address))
    }

  },
  getters: {
    addstr(state) {
      const {
        provinceName,
        cityName,
        countyName,
        detailInfo
      } = state.address
      if (!provinceName) return ''
      return provinceName + cityName + countyName + detailInfo
    }
  }

}
